package com.wits.platform.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;

import com.wits.platform.common.utils.PageUtil;
import com.wits.platform.dao.MenuDao;
import com.wits.platform.dao.RoleDao;
import com.wits.platform.dao.UserDao;
import com.wits.platform.entity.Menu;
import com.wits.platform.entity.User;
import com.wits.platform.web.mvc.PageParam;

@Component
public class CommonService {
	
	@Resource
	private RoleDao roleDao;
	
	@Resource
	private UserDao userDao;
	
	@Resource
	private MenuDao menuDao;
	
	public Page<User> findUserPage(Map<String, Object> filterParams,PageParam page){
		PageRequest pageRequest = PageUtil.buildPageRequest(page);
		Specification<User> spec = PageUtil.buildSpecification(User.class,filterParams);
		return userDao.findAll(spec, pageRequest);
	}
	
	
	/**
	 * 查询所有没有这个角色的用户
	 * @param filterParams
	 * @param page
	 * @param roleId 
	 * @return
	 */
	public Page<User> findUserNoRole(Map<String, Object> filterParams,PageParam page,String roleId,String excludeUserId){
		return userDao.findUserNoRole(filterParams,page,roleId,excludeUserId);
	}

	/**
	 * 查询有某个角色的所有用户
	 * @param filterParams
	 * @param page
	 * @param roleId
	 * @return
	 */
	public List<User> findUserByRole(Map<String, Object> filterParams,String roleId) {
		return userDao.findUserByRole(filterParams,roleId);
	}

	public Page<User> findUserPageByRole(Map<String, Object> searchParams,PageParam page, String roleId) {
		return userDao.findUserPageByRole(searchParams,page,roleId);
	}
	
	public Page<Menu> findMenuPageByRole(Map<String, Object> searchParams,PageParam page, String roleId) {
		return menuDao.findMenuPageByRole(searchParams,page,roleId);
	}
	
}
